package cn.doitedu.utils;

import cn.doitedu.pojo.CombineCondition;
import cn.doitedu.pojo.EventCondition;
import cn.doitedu.pojo.RuleCondition;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @create: 2021-11-12 19:24
 * @author: 静如海的男人
 * @program: eagle-text
 * 规则模拟器
 **/
@SuppressWarnings("all")
public class RuleSimulator {

    public static RuleCondition getRule() {
        RuleCondition ruleCondition = new RuleCondition();
        ruleCondition.setRuleId("原计划");

        //事先定义好的触发行为规则
        EventCondition eventParam = new EventCondition();
        eventParam.setEventId("E");
        HashMap<String, String> map = new HashMap<>();
        map.put("p2","v1");
        eventParam.setProperties(map);
        ruleCondition.setTriggerEvent(eventParam);

        //事先定义好的用户画像规则
        HashMap<String, String> map2 = new HashMap<>();
        map2.put("tag10","v1");
        map2.put("tag1","v1");
        ruleCondition.setProfileCondition(map2);

        //事先定义好的用户历史行为 次数 序列
        ArrayList<CombineCondition> combineConditions = new ArrayList<>();
        //事先定义好的用户历史行为 次数
        CombineCondition ccn1 = new CombineCondition();
        ccn1.setSql(
                "select eventId from eagle_detail where deviceId = ? " +
                        "and timeStamp >= ? and timeStamp <= ? order by timeStamp asc"
        );
        ccn1.setStartTime(1636473600000L);
        ccn1.setEndTime(1637078399000L);
        ccn1.setRegex("(A)");
        ccn1.setMinLimit(2);
        ccn1.setMaxLimit(Integer.MAX_VALUE);
        ArrayList<EventCondition> eventParams = new ArrayList<>();
        EventCondition eventParam1 = new EventCondition();
        eventParam1.setEventId("A");
        eventParams.add(eventParam1);
        ccn1.setEventConditions(eventParams);

        //事先定义好的用户历史行为 序列
        CombineCondition ccn2 = new CombineCondition();
        ccn2.setSql(
                "select eventId from eagle_detail where deviceId = ? " +
                        "and timeStamp >= ? and timeStamp <= ? order by timeStamp asc"
        );
        ccn2.setStartTime(1636473600000L);
        ccn2.setEndTime(1637078399000L);
        ccn2.setRegex("(.*?A.*?B.*?C)");
        ccn2.setMinLimit(1);
        ccn2.setMaxLimit(Integer.MAX_VALUE);

        ArrayList<EventCondition> eventParams2 = new ArrayList<>();

        EventCondition eventParam2 = new EventCondition();
        eventParam2.setEventId("B");
        EventCondition eventParam3 = new EventCondition();
        eventParam3.setEventId("X");
        EventCondition eventParam4 = new EventCondition();
        eventParam4.setEventId("W");

        eventParams2.add(eventParam2);
        eventParams2.add(eventParam3);
        eventParams2.add(eventParam4);
        ccn2.setEventConditions(eventParams2);

        combineConditions.add(ccn1);
        combineConditions.add(ccn2);

        ruleCondition.setCombineCondition(combineConditions);


        return ruleCondition;
    }
}
